import { defineStore } from 'pinia'
import { getStartAndEndTime } from '@/views/advert/common'

const useAdvertStore = defineStore('advert-info', {
  state: () => {
    return {
      targetShowKeys: ['impressions', 'clicks', 'cost', 'cpc'] as string[],
      targetClickKeys: ['impressions', 'clicks'] as string[], //选中展示的图表指标
      salesTargetClickKeys: ['purchasesSale', 'saleAmount'] as string[], //销售看板选中展示的图表指标
      darftInfo: {} as any, //草稿箱信息
      currentCampaign: {} as any, //当前选中的广告活动
      currentShop: {} as any, //当前选中的店铺
      currentGroup: {} as any, //当前行选中的广告组
      currentLevel: 'campaign', //当前所属层级，一般是campaign和adGroup用于判断详情展示内容
      currentSearchTime: getStartAndEndTime('last_30_days'), //当前查询时间，
      currentSearchVal: {}, //当前查询条件
    }
  },
  actions: {
    // 显示的指标趋势
    changeTargetShowKey(keys: Array<string>) {
      this.targetShowKeys = keys
    },
    // 选中的图表指标
    changeTargetClickKey(keys: Array<string>) {
      this.targetClickKeys = keys
    },
    // 选中的销售图表指标
    changeSalesTargetClickKey(keys: Array<string>) {
      this.salesTargetClickKeys = keys
    },
    // 广告活动草稿箱信息
    changeDarftInfo(val: any) {
      this.darftInfo = val
    },
    // //当前选中的广告活动
    changeCampaignIn(val: any) {
      this.currentCampaign = val
    },
    //当前选中的广告组
    changeGroup(val: any) {
      this.currentGroup = val
    },
    //当前选中的店铺
    changeShop(val: any) {
      this.currentShop = val
    },
    //当前所属的层级
    changeCurrentLevel(val: string) {
      this.currentLevel = val
    },
    restorEeditSpCampaign() {
      this.darftInfo = {}
    },
    // 当前查询时间范围
    changeSearchTime(val: any) {
      this.currentSearchTime = val?.[0] ? val : getStartAndEndTime('last_30_days')
    },
    // 查询条件
    changeSearchVal(val: any) {
      this.currentSearchVal = val
    },
  },
  presist: {
    enable: true,
    resetToState: true,
    option: {
      exclude: ['currentSearchVal'],
    },
  },
})

export default useAdvertStore
